// pages/tixian/tixian.js
const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgurl:app.data.imgurl,
        userinfo:[],
        tixian:0,//可提现金额
        money: 0,//提现金额
        btnable: true,
        shouxufei:0,
        minmoney:0,
        usermoney:0,//今日提现多少
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        //获取配置信息
        this.getApp
        //个人信心
        this.setData({
          userinfo:app.globalData.userinfo
        });
        //获取手机费比例
        this.getpro();
    },
    getpro: function () {
        var that = this
        var userid = app.globalData.userId;
        util.httpRrquest(app.data.rooturl + 'user/getTixianPro', 'GET', {userid:userid})
            .then(function (response) {

                that.setData({
                    shouxufei: response.data.data[0],
                    minmoney: response.data.data[1]
                });
            }, function (error) {
                console.log(error);
            });
    },
    //输入框监听
    bindinput: function (e) {
        //console.log(e);
        var value = e.detail.value;
        this.setData({
            money: value,
        })
    },
    //提现申请
    addcashadvance:function(){
        var that = this
        var money=Math.abs(parseFloat(that.data.money));
        if (isNaN(money)) {
            wx.showToast({
                title: '请正确输入提现金额',
                icon: 'none'
            })
            
            return;
        }
        if (money<=0){
            wx.showToast({
                title: '请正确输入提现金额',
                icon: 'none'
            })
            
            return;
        }
        if (money > this.data.userinfo.userBalance) {
            wx.showToast({
                title: '提现金额高于可提现金额',
                icon: 'none'
            })
            
            return;
        } 
        if (money < this.data.minmoney) {
            wx.showToast({
                title: '提现金额不能小于' + this.data.minmoney+'元',
                icon: 'none'
            })
            
            return;
        }
       
        if (!that.data.btnable) {
            return;
        }
        this.setData({
            btnable: false,
        })
        var userid = app.globalData.userId;
        var pronum=money*that.data.shouxufei/100;
        var truemoney=money-pronum;
        util.httpRrquest(app.data.rooturl + 'user/addTixian', 'POST', {userid:userid,pronum:pronum,truemoney:truemoney, money: that.data.money})
        .then(function (response) {
            wx.showToast({
                title: response.data.msg,
                icon: 'none',
                duration: 2000
            })
            setTimeout(function () {
                wx.navigateBack({
                    delta: 1
                })
            }, 2000);
        }, function (error) {
            console.log(error);
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        var shareinfo = app.setShareMessage();
        console.log(shareinfo);
        return {
            title: shareinfo.title,
            path: shareinfo.path,
            imageUrl: shareinfo.imageUrl,
            success: (res) => {
                wx.showToast({
                    title: "分享成功",
                    icon: 'loading'
                })
            }
        }
    },
})